package conf;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.Serializable;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollBar;
import javax.swing.JScrollPane;
import javax.swing.plaf.basic.BasicScrollBarUI;

public class MyScrollBar extends JScrollBar implements Serializable{
	public MyScrollBar() {
		super();
		setUI(new MyScrollBarUI());
	}
	
	public MyScrollBar(int orientation) {
		super(orientation, 0, 10, 0, 100);
		setUI(new MyScrollBarUI());
    }
	
	class MyScrollBarUI extends BasicScrollBarUI {

		protected void installComponents(){
			super.installComponents();
			incrButton.addActionListener(new ActionListener(){
				public void actionPerformed(ActionEvent e) {
					System.out.println("incrButton");
				}
			});
			decrButton.addActionListener(new ActionListener(){
				public void actionPerformed(ActionEvent e) {
					System.out.println("decrButton");
				}
			});
		}
	}
	
	public static void main(String[] args) {
		JFrame frame = new JFrame();
		frame.setSize(200, 200);
		frame.setLocationRelativeTo(null);//居中
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		Container content = frame.getContentPane();
		JPanel pnl = new JPanel();
		pnl.setPreferredSize(new Dimension(200,500));
		JScrollPane scrPane = new JScrollPane(pnl);
		scrPane.setVerticalScrollBar(new MyScrollBar());
		content.add(scrPane);
		frame.setVisible(true);
	}
}